package com.example.park2212.payer

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_base.entity.PayerBeanItem
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.R
import com.example.park2212.databinding.ActivityPayerBinding

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/payer/PayerActivity")
class PayerActivity : BaseActivity<ActivityPayerBinding,PayerViewModel>() {
    lateinit var payerAdapter: PayerAdapter
    val list = mutableListOf<PayerBeanItem>()
    override fun initView() {

        binding.payerHead.headerTitle.setText("收银台")
        binding.payerHead.headerAdd.setOnClickListener {
            ARouter.getInstance().build("/app/payer/PayerAddActivity").navigation()
        }
        binding.payerHead.headerBack.setOnClickListener {
            finish()
        }

        payerAdapter = PayerAdapter()
        binding.rvPayer.adapter = payerAdapter
        binding.rvPayer.layoutManager = LinearLayoutManager(this)
        viewModel.getPayer(1)

        payerAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/app/payer/PayerDetailActivity")
                .withString("yid",payerAdapter.data[position].id.toString()).navigation()
        }


    }

    override fun initData() {
        viewModel.getPayerSuccess.observe(this){
            list.addAll(it.filter { it.paymentStatus == "未缴费" })
            payerAdapter.data.clear()
            payerAdapter.data.addAll(it)
            payerAdapter.notifyDataSetChanged()
        }
    }



}